package cn.growthgate.fgo.entity;

import com.baomidou.mybatisplus.enums.IdType;
import java.util.Date;
import com.baomidou.mybatisplus.annotations.TableId;
import com.baomidou.mybatisplus.activerecord.Model;
import com.baomidou.mybatisplus.annotations.TableName;
import java.io.Serializable;
import java.math.BigDecimal;

/**
 * <p>
 * 图片
 * </p>
 *
 * @author GrowthGate
 * @since 2019-04-21
 */
@TableName("t_image")
public class Image extends Model<Image> {

	private static final long serialVersionUID = 1L;

	/**
	 * 主键id
	 */
	@TableId(value = "id", type = IdType.AUTO)
	private Long id;

	/**
	 * 随机id
	 */
	private String uuid;

	/**
	 * 名称
	 */
	private String name;

	/**
	 * 完整路径
	 */
	private String path;

	/**
	 * 大小（B）
	 */
	private Long length;

	/**
	 * 高
	 */
	private Integer height;

	/**
	 * 宽
	 */
	private Integer width;

	/**
	 * 上传时间
	 */
	private Date uploadtime;

	/**
	 * 年
	 */
	private Integer year;

	/**
	 * 月
	 */
	private Integer month;

	/**
	 * 日
	 */
	private Integer day;

	/**
	 * 上传人id
	 */
	private Long userId;

	/**
	 * 实体类名称
	 */
	private String entityName;

	/**
	 * 实体id
	 */
	private Long entityId;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUuid() {
		return uuid;
	}

	public void setUuid(String uuid) {
		this.uuid = uuid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPath() {
		return path;
	}

	public void setPath(String path) {
		this.path = path;
	}

	public Long getLength() {
		return length;
	}

	public void setLength(Long length) {
		this.length = length;
	}

	public Integer getHeight() {
		return height;
	}

	public void setHeight(Integer height) {
		this.height = height;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	public Date getUploadtime() {
		return uploadtime;
	}

	public void setUploadtime(Date uploadtime) {
		this.uploadtime = uploadtime;
	}

	public Integer getYear() {
		return year;
	}

	public void setYear(Integer year) {
		this.year = year;
	}

	public Integer getMonth() {
		return month;
	}

	public void setMonth(Integer month) {
		this.month = month;
	}

	public Integer getDay() {
		return day;
	}

	public void setDay(Integer day) {
		this.day = day;
	}

	public Long getUserId() {
		return userId;
	}

	public void setUserId(Long userId) {
		this.userId = userId;
	}

	public String getEntityName() {
		return entityName;
	}

	public void setEntityName(String entityName) {
		this.entityName = entityName;
	}

	public Long getEntityId() {
		return entityId;
	}

	public void setEntityId(Long entityId) {
		this.entityId = entityId;
	}

	@Override
	protected Serializable pkVal() {
		return this.id;
	}

	@Override
	public String toString() {
		return "Image{" + "id=" + id + ", uuid=" + uuid + ", name=" + name + ", path=" + path + ", length=" + length
				+ ", height=" + height + ", width=" + width + ", uploadtime=" + uploadtime + ", year=" + year
				+ ", month=" + month + ", day=" + day + ", userId=" + userId + ", entityName=" + entityName
				+ ", entityId=" + entityId + "}";
	}
	
	public String getSize() {
		Long length = getLength();
		if (length == null || length < 0) {
			return "";
		} else if (length < 1024) {
			return length + "B";
		} else if (length < 1024 * 10) {
			// 与windows系统相同的方式，向下取整
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024))
					.setScale(2, BigDecimal.ROUND_DOWN).toString() + "KB";
		} else if (length < 1024 * 100) {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024))
					.setScale(1, BigDecimal.ROUND_DOWN).toString() + "KB";
		} else if (length < 1024 * 1024) {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024))
					.setScale(0, BigDecimal.ROUND_DOWN).toString() + "KB";
		} else if (length < 1024 * 1024 * 10) {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024 * 1024))
					.setScale(2, BigDecimal.ROUND_DOWN).toString() + "MB";
		} else if (length < 1024 * 1024 * 100) {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024 * 1024))
					.setScale(1, BigDecimal.ROUND_DOWN).toString() + "MB";
		} else if (length < 1024 * 1024 * 1024) {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024 * 1024))
					.setScale(0, BigDecimal.ROUND_DOWN).toString() + "MB";
		} else {
			return BigDecimal.valueOf(length).divide(BigDecimal.valueOf(1024 * 1024 * 1024))
					.setScale(0, BigDecimal.ROUND_DOWN).toString() + "GB";
		}
	}

}
